package com.itpeng.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itpeng.dao.MemberDao;
import com.itpeng.pojo.Member;
import com.itpeng.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @Aythor:彭彦钦
 * @Data: 2020/9/26  22:03
 */
@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao memberDao;

    /**
     * 根据手机号查询用户
     * @param telephone
     * @return
     */
    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    /**
     * 添加用户
     * @param member
     */
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    /**
     * 根据数组中的日期获得近一年汇总每月的会员数量集合
     * @param months
     * @return
     */
    @Override
    public List<Integer> getMemberReport(List<String> months) {
        List<Integer> list = new ArrayList<Integer>();
        //遍历集合，查询12次
        for (String month : months) {
            String endMonth = month + "-31";
            int count = memberDao.findByBetweenDate(endMonth);
            list.add(count);
        }

        return list;
    }
}
